package com.webchat.pgc.controller.mall;

import com.webchat.common.bean.APIResponseBean;
import com.webchat.common.bean.APIResponseBeanUtil;
import com.webchat.domain.vo.request.mall.MallProductOperateVO;
import com.webchat.domain.vo.request.mall.MallSPURequestVO;
import com.webchat.domain.vo.response.mall.MallSPUDetailVO;
import com.webchat.pgc.service.mall.MallSKUService;
import com.webchat.pgc.service.mall.MallSPUService;
import com.webchat.rmi.pgc.mall.MallProductClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;


@RestController
public class MallProductController implements MallProductClient {

    @Autowired
    private MallSPUService mallSPUService;

    @Autowired
    private MallSKUService mallSKUService;

    @Override
    public APIResponseBean<Long> save(@RequestBody MallSPURequestVO spuRequest) {
        Long productId = mallSPUService.save(spuRequest);
        return APIResponseBeanUtil.success(productId);
    }

    @Override
    public APIResponseBean<Boolean> publish(@RequestBody MallProductOperateVO productOperateVO) {

        boolean res = mallSPUService.publish(productOperateVO.getProductId(), productOperateVO.getOperator());
        return APIResponseBeanUtil.success(res);
    }

    @Override
    public APIResponseBean<Boolean> invoke(@RequestBody MallProductOperateVO productOperateVO) {

        boolean res = mallSPUService.invoke(productOperateVO.getProductId(), productOperateVO.getOperator());
        return APIResponseBeanUtil.success(res);
    }

    @Override
    public APIResponseBean<Boolean> delete(@RequestBody MallProductOperateVO productOperateVO) {

        boolean res = mallSPUService.delete(productOperateVO.getProductId(), productOperateVO.getOperator());
        return APIResponseBeanUtil.success(res);
    }

    @Override
    public APIResponseBean<MallSPUDetailVO> detail(Long productId, String userId) {
        MallSPUDetailVO product = mallSPUService.detail(productId, userId);
        return APIResponseBeanUtil.success(product);
    }

    @Override
    public APIResponseBean<MallSPUDetailVO> detailBySku(Long skuId) {
        MallSPUDetailVO product = mallSPUService.detailBySku(skuId);
        return APIResponseBeanUtil.success(product);
    }

    @Override
    public APIResponseBean<Map<Long, MallSPUDetailVO>> batchGetBySku(@RequestBody List<Long> skuIdList) {
        Map<Long, MallSPUDetailVO> productMap = mallSPUService.batchGetProductBySkuIdList(skuIdList);
        return APIResponseBeanUtil.success(productMap);
    }

    @Override
    public APIResponseBean<Map<Long, Long>> batchGetSkuShopId(@RequestBody List<Long> skuIdList) {
        Map<Long, Long> skuShopMap = mallSKUService.batchGetSkuShopId(skuIdList);
        return APIResponseBeanUtil.success(skuShopMap);
    }
}
